<?php

//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Controller;

use AuctionCore\Account\Back\Employee;
use AuctionCore\Other\Reserve as Reserve;
use AuctionCore\Common\Page;
use AuctionCore\System\AuctionException;

/**
 * 定制购车
 * @author Xmh
 */
class ReserveController extends BaseController {

    public function __construct() {
        parent::__construct();
        //页面头部信息
        $head = C('HEAD_INDEX');
        $this->assign("web_title", $head['title']);
        $this->assign("web_keywords", $head['keywords']);
        $this->assign("web_description", $head['description']);
        $this->emp_id = $this->user_info['emp_id'];

        $this->Reserve = new Reserve();
        //模板赋值
        $this->assign("emp_id", $this->emp_id);
    }

    /**
     * 首页
     */
    public function index() {
        $this->display();
    }

    public function track() {
        $this->display();
    }

    public function reserve_list() {
        $page = I("get.p", 1);
        $size = 10;
        $params = array();
        $params['id'] = I('get.id');
        $params['name'] = I('get.name');
        $params['phone'] = I('get.phone');
        $params['car_no'] = I('get.car_no');
        $params['car_type'] = I('get.car_type');
        $params['comefrom'] = I('get.comfrom');
        $params['start_time'] = I('get.start_time');
        $params['end_time'] = I('get.end_time');
        $params['status'] = I('get.status');
        $params['emp_id'] = $this->emp_id;
        //获取list
        $result = $this->Reserve->get_reserve_list($page, $size, $params);
        $list = empty($result['list']) ? array() : $result['list'];
        //分页
        $Page = new \AuctionCore\Common\AjaxPage($result['total'], $size, "get_page");
        $Page->setConfig('theme', " %totalRow% %header% %nowPage%/%totalPage% 页 %first% %upPage% %prePage% %linkPage% %nextPage% %downPage%  %end% %jumpform%");
//        dump($list);
        $show = $Page->show();          // 分页显示输出
        $this->assign('page', $show);   // 赋值分页输出
        $this->assign('list', $list);
        $this->assign('p', $page);
        $this->assign('status', $params['status']);
        $this->assign('total', $result['total']);
        $this->display();
    }

    /**
     * 预约页面
     */
    public function reserve_deal() {
        $id = I('get.id/d');
        if ($id < 1) {
            $this->helpJsonResult(400, '预约信息不存在或已删除');
        }
        $reserve = $this->Reserve->get_reserve_info($id);
        $this->assign("reserve", $reserve);
        $this->display();
    }

    /**
     * 处理预约
     */
    public function do_reserve_deal() {
        $id = I('post.id/d');
        if ($id < 1) {
            $this->helpJsonResult(400, '预约信息不存在或已删除');
        }
        $remark = I('post.remark');
        $status = I('post.status');
        if (empty($remark)) {
            $this->helpJsonResult(400, '请填写备注');
        }
        $data['re_id'] = $id;
        $data['remark'] = $remark;
        $data['status'] = $status;
        $data['emp_id'] = $this->emp_id;
        $res = $this->Reserve->update_reserve_post($data);
        if ($res === false) {
            $this->helpJsonResult(500, '处理失败');
        }
        $this->helpJsonResult(200, '处理成功');
    }

}
